home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / j109lxa4.tar / icmpdump.c < prev    next >
C/C++ Source or Header  |  1994-06-04  |  2KB  |  100 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "netuser.h"
  6. #include "icmp.h"
  7. #include "trace.h"
  8. #include "ip.h"
  9.  
  10. /* Dump an ICMP header */
  11. void
  12. #ifdef MONITOR
  13. icmp_dump(fp,bpp,source,dest,check,mon)
  14. int mon;
  15. #else
  16. icmp_dump(fp,bpp,source,dest,check)
  17. #endif
  18. FILE *fp;
  19. struct mbuf **bpp;
  20. int32 source,dest;
  21. int check;        /* If 0, bypass checksum verify */
  22. {
  23.     struct icmp icmp;
  24.     int16 csum;
  25.  
  26.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  27.         return;
  28.     csum = cksum(NULLHEADER,*bpp,len_p(*bpp));
  29.     
  30.     ntohicmp(&icmp,bpp);
  31.     
  32. #ifdef MONITOR
  33.     if (mon)
  34.         fprintf(fp, "%s", smsg(Icmptypes,ICMP_TYPES,(unsigned)uchar(icmp.type)));
  35.     else
  36. #endif
  37.     fprintf(fp,"ICMP: type %s",smsg(Icmptypes,ICMP_TYPES,(unsigned)uchar(icmp.type)));
  38.  
  39.     switch(uchar(icmp.type)){
  40.     case ICMP_DEST_UNREACH:
  41. #ifdef MONITOR
  42.         if (mon)
  43.             fprintf(fp, "%s", smsg(Unreach,NUNREACH,(unsigned)uchar(icmp.code)));
  44.         else
  45. #endif
  46.         fprintf(fp," code %s",smsg(Unreach,NUNREACH,(unsigned)uchar(icmp.code)));
  47.         break;
  48.     case ICMP_REDIRECT:
  49. #ifdef MONITOR
  50.         if (mon)
  51.             fprintf(fp, "%s", smsg(Redirect,NREDIRECT,(unsigned)uchar(icmp.code)));
  52.         else
  53. #endif
  54.         fprintf(fp," code %s",smsg(Redirect,NREDIRECT,(unsigned)uchar(icmp.code)));
  55.         fprintf(fp," new gateway %s",inet_ntoa(icmp.args.address));
  56.         break;
  57.     case ICMP_TIME_EXCEED:
  58. #ifdef MONITOR
  59.         if (mon)
  60.             fprintf(fp, "%s", smsg(Exceed,NEXCEED,(unsigned)uchar(icmp.code)));
  61.         else
  62. #endif
  63.         fprintf(fp," code %s",smsg(Exceed,NEXCEED,(unsigned)uchar(icmp.code)));
  64.         break;
  65.     case ICMP_PARAM_PROB:
  66.         fprintf(fp," pointer %u",icmp.args.pointer);
  67.         break;
  68.     case ICMP_ECHO:
  69.     case ICMP_ECHO_REPLY:
  70.     case ICMP_INFO_RQST:
  71.     case ICMP_INFO_REPLY:
  72.     case ICMP_TIMESTAMP:
  73.     case ICMP_TIME_REPLY:
  74. #ifdef MONITOR
  75.         if (!mon)
  76. #endif
  77.         fprintf(fp," id %u seq %u",icmp.args.echo.id,icmp.args.echo.seq);
  78.         break;
  79.     }
  80.     if(check && csum != 0){
  81.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  82.     }
  83.     fprintf(fp,"\n");
  84.     /* Dump the offending IP header, if any */
  85.     switch(icmp.type){
  86.     case ICMP_DEST_UNREACH:
  87.     case ICMP_TIME_EXCEED:
  88.     case ICMP_PARAM_PROB:
  89.     case ICMP_QUENCH:
  90.     case ICMP_REDIRECT:
  91.         fprintf(fp,"Returned ");
  92. #ifdef MONITOR
  93.         ip_dump(fp,bpp,0,mon);
  94. #else
  95.         ip_dump(fp,bpp,0);
  96. #endif
  97.     }
  98. }
  99.  
  100.